home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’95 / NetFractal™ / ES stuff□ / CNetDemoApp.cp < prev    next >
Encoding:
Text File  |  1995-06-24  |  7.4 KB  |  277 lines  |  [TEXT/MMCC]

  1. // ===========================================================================
  2. //    CNetDemoApp.cp                ©1995 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4. //
  5. //    Example program showing how to use UModalDialogs
  6.  
  7. #include "CNetDemoApp.h"
  8.  
  9. #include "InPoint.h"
  10. #include "OutPoint.h"
  11. #include "APane.h"
  12. #include "AWindow.h"
  13. #include "DrawPoint.h"
  14. #include "BWindow.h"
  15.  
  16. #include <LApplication.h>
  17. #include <LGrowZone.h>
  18. #include <LWindow.h>
  19. #include <UMemoryMgr.h>
  20. #include <UDrawingState.h>
  21. #include <URegistrar.h>
  22. #include <UReanimator.h>
  23.  
  24. #include <LEditField.h>
  25. #include <LTabGroup.h>
  26. #include <LCaption.h>
  27. #include <LRadioGroup.h>
  28. #include <LStdControl.h>
  29. #include <LDialogBox.h>
  30. #include <UModalDialogs.h>
  31. #include <PP_Messages.h>
  32.  
  33. #include <string.h>
  34.  
  35.  
  36. const ResIDT    WIND_NewSession = 128;
  37. const PaneIDT    pTCPButton        = 1;
  38. const PaneIDT    pAtalkButton    = 2;
  39. const PaneIDT    pAddress        = 11;
  40.  
  41. /*
  42. const ResIDT    WIND_Dashboard    = 200;
  43. const PaneIDT    capt_Number        = 301;
  44. const PaneIDT    capt_String        = 302;
  45.  
  46. const MessageT    msg_SetNumber    = 1000;
  47. const MessageT    msg_SetString    = 2000;
  48. const MessageT    msg_SetBoth        = 3000;
  49.  
  50. const ResIDT    WIND_SetNumber    = 1000;
  51. const PaneIDT    edit_Number        = 1001;
  52.  
  53. const ResIDT    WIND_SetString    = 2000;
  54. const PaneIDT    edit_String        = 2001;
  55.  
  56. const ResIDT    WIND_SetBoth    = 3000;
  57. const PaneIDT    edit_Number1    = 3001;
  58. const PaneIDT    edit_String1    = 3002;
  59. */
  60.  
  61.  
  62. // ===========================================================================
  63. //        • Main Program
  64. // ===========================================================================
  65.  
  66. void main(void)
  67. {
  68.     try {
  69.                                         // Set Debugging options
  70.         SetDebugThrow_(debugAction_Alert);
  71.         SetDebugSignal_(debugAction_Alert);
  72.     
  73.         InitializeHeap(3);                // Initialize Memory Manager
  74.                                         // Parameter is number of Master Pointer
  75.                                         //   blocks to allocate
  76.         
  77.                                         // Initialize standard Toolbox managers
  78.         UQDGlobals::InitializeToolbox(&qd);
  79.         InitOpenTransport();    
  80.     
  81.         new LGrowZone(20000);            // Install a GrowZone function to catch
  82.                                         //    low memory situations.
  83.                                         //    Parameter is size of reserve memory
  84.                                         //    block to allocated. The first time
  85.                                         //    the GrowZone function is called,
  86.                                         //    there will be at least this much
  87.                                         //    memory left (so you'll have enough
  88.                                         //    memory to alert the user or finish
  89.                                         //    what you are doing).
  90.         
  91.         CNetDemoApp    theApp;            // Create instance of your Application
  92.         theApp.Run();                    //   class and run it
  93.     }
  94.     catch(...) {
  95.         DebugStr("\pSomething's really hosed");
  96.     }
  97. }
  98.  
  99.  
  100. // ===========================================================================
  101. //        • CNetDemoApp Class
  102. // ===========================================================================
  103.  
  104. // ---------------------------------------------------------------------------
  105. //        • CNetDemoApp
  106. // ---------------------------------------------------------------------------
  107. //    Constructor
  108.  
  109. CNetDemoApp::CNetDemoApp()
  110. {
  111.         // Register classes for objects created from 'PPob' resources
  112.         // For PowerPlant classes, you can copy the necessary RegisterClass
  113.         // calls from PPobClasses.cp
  114.         //
  115.         // For your own classes, you must use the same four-character ID as
  116.         // you specify in the 'PPob' resource (or in Constructor).
  117.         // PowerPlant reserves all ID's composed entirely of lower case
  118.         // letters.
  119.         //
  120.         // The convention in PowerPlant is to define a local enumerated
  121.         // constant called class_ID for the four-character ID of each class.
  122.         
  123.     URegistrar::RegisterClass(LWindow::class_ID, LWindow::CreateWindowStream);
  124.     URegistrar::RegisterClass(LEditField::class_ID, LEditField::CreateEditFieldStream);
  125.     URegistrar::RegisterClass(LTabGroup::class_ID, LTabGroup::CreateTabGroupStream);
  126.     URegistrar::RegisterClass(LCaption::class_ID, LCaption::CreateCaptionStream);
  127.     URegistrar::RegisterClass(LStdButton::class_ID, LStdButton::CreateStdButtonStream);
  128.     URegistrar::RegisterClass(LStdRadioButton::class_ID, LStdRadioButton::CreateStdRadioButtonStream);
  129.     URegistrar::RegisterClass(LRadioGroup::class_ID, LRadioGroup::CreateRadioGroupStream);
  130.     URegistrar::RegisterClass(LDialogBox::class_ID, LDialogBox::CreateDialogBoxStream);
  131.     URegistrar::RegisterClass(APane::class_ID, APane::CreateAPaneStream);
  132.     URegistrar::RegisterClass(AWindow::class_ID, AWindow::CreateWindowStream);
  133.     URegistrar::RegisterClass(BWindow::class_ID, BWindow::CreateWindowStream);
  134. }
  135.  
  136.  
  137. // ---------------------------------------------------------------------------
  138. //        • ~CNetDemoApp
  139. // ---------------------------------------------------------------------------
  140. //    Destructor
  141.  
  142. CNetDemoApp::~CNetDemoApp()
  143. {
  144.         // +++ Add code here to cleanup (if necessary) before quitting
  145. }
  146.  
  147.  
  148. // ---------------------------------------------------------------------------
  149. //        • ObeyCommand
  150. // ---------------------------------------------------------------------------
  151. //    Respond to commands
  152.  
  153. Boolean
  154. CNetDemoApp::ObeyCommand(
  155.     CommandT    inCommand,
  156.     void        *ioParam)
  157. {
  158.     Boolean    cmdHandled = true;
  159.     
  160.     switch (inCommand) {
  161.         
  162.         case cmd_New:
  163.         case 999:
  164.             SpawnSender(inCommand != cmd_New);            // yes this is ugly... deal with it
  165.             break;
  166.     
  167.         // +++ Add cases here for the commands you handle
  168.         //        Remember to add same cases to FindCommandStatus below
  169.         //        to enable/disable the menu items for the commands
  170.     
  171.         default:
  172.             cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
  173.             break;
  174.     }
  175.     
  176.     return cmdHandled;
  177. }
  178.  
  179.  
  180. // ---------------------------------------------------------------------------
  181. //        • FindCommandStatus
  182. // ---------------------------------------------------------------------------
  183. //    Pass back status of a (menu) command
  184.  
  185. void
  186. CNetDemoApp::FindCommandStatus(
  187.     CommandT    inCommand,
  188.     Boolean        &outEnabled,
  189.     Boolean        &outUsesMark,
  190.     Char16        &outMark,
  191.     Str255        outName)
  192. {
  193.     outUsesMark = false;
  194.     
  195.     switch (inCommand) {
  196.     
  197.         // +++ Add cases here for the commands you handle.
  198.         //
  199.         //        Set outEnabled to TRUE for commands that can be executed at
  200.         //        this time.
  201.         //
  202.         //        If the associated menu items can have check marks, set
  203.         //        outUsesMark and outMark accordingly.
  204.         //
  205.         //        Set outName to change the name of the menu item
  206.     
  207.         case cmd_New:
  208.         case 999:
  209.             outEnabled = true;
  210.             break;
  211.     
  212.         default:
  213.             LApplication::FindCommandStatus(inCommand, outEnabled, outUsesMark,
  214.                                 outMark, outName);
  215.             break;
  216.     }
  217. }
  218.  
  219.  
  220.  
  221. void
  222. CNetDemoApp::SpawnSender(
  223.     Boolean inSender)
  224.  
  225. {
  226.     StDialogHandler dlog(WIND_NewSession, this);
  227.     MessageT msg = 0;
  228.     
  229.     while (!msg)
  230.         msg = dlog.DoDialog();
  231.  
  232.     if (msg == msg_Cancel)
  233.         return;
  234.  
  235.     char configstr[80];
  236.     
  237.     LStdRadioButton* tcpBut = (LStdRadioButton*) dlog.GetDialog()->FindPaneByID(pTCPButton);
  238.     
  239.     if (tcpBut->GetValue())
  240.         strcpy(configstr, "udp");
  241.     else
  242.         strcpy(configstr, "ddp");
  243.     
  244.     dlog.GetDialog()->Hide();
  245.  
  246.     // for now we just create a sender
  247.     
  248.     LWindow *dWindow = NULL;
  249.  
  250.     try {
  251.     
  252.         if (inSender) {
  253. /*
  254.             BWindow *window = (BWindow *)LWindow::CreateWindow(130, this);
  255.             dWindow = window;
  256.  
  257.             OutPoint *point = new OutPoint(configstr, address, OUR_PORT);
  258.             window->SetOutPoint(point);
  259. */
  260.         } else {
  261.             AWindow *window = AWindow::CreateWindow(129, this);
  262.             dWindow = window;
  263.             APane *aPane = (APane *)window->FindPaneByID(4711);
  264.             window->SetScreenTarget(aPane->GetScreenTarget());
  265.  
  266.             DrawPoint* theNetPoint;
  267.             theNetPoint = new DrawPoint(configstr, "", OUR_PORT, aPane);
  268.             window->SetNetPoint(theNetPoint);
  269.         }
  270.     } catch(...) {
  271.         DebugStr("\pCouldn't establish NetPoint");
  272.         // couldn't get netpoint
  273.         delete dWindow;
  274.     }
  275. }
  276.  
  277.